using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AppControl
{
    public partial class frmRequestResponseHeaders : Form
    {
        public frmRequestResponseHeaders()
        {
            InitializeComponent();
            this.Text = "HTTP + HTTPS Request Response Headers!";
            this.FormClosing += new FormClosingEventHandler(frmRequestResponseHeaders_FormClosing);
            this.toolStripButtonClear.Click += new EventHandler(toolStripButtonClear_Click);
            this.toolStripButtonClose.Click += new EventHandler(toolStripButtonClose_Click);
            this.toolStripButtonSave.Click += new EventHandler(toolStripButtonSave_Click);
        }

        public void AppendToLog(string Text)
        {
            //richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.AppendText(Environment.NewLine + Text + Environment.NewLine);
            //richTextBox1.SelectionStart = richTextBox1.Text.Length;
        }

        void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog m_dlgSave = new SaveFileDialog();
            m_dlgSave.DefaultExt = "txt";
            m_dlgSave.FileName = "FileName";
            m_dlgSave.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            m_dlgSave.Title = "Save File";
            m_dlgSave.InitialDirectory = Environment.CurrentDirectory;
            if (m_dlgSave.ShowDialog(this) == DialogResult.OK)
            {
                using (StreamWriter sw = new StreamWriter(m_dlgSave.FileName))
                {
                    sw.Write(richTextBox1.Text);
                }
            }
        }

        void toolStripButtonClose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        void toolStripButtonClear_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        void frmRequestResponseHeaders_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                toolStripButtonClose_Click(this, EventArgs.Empty);
            }
        }
    }
}